<?php
/*
Template Name: Qbased
*/
?>

<?php get_header(); ?>


<?php
 $querystr = "
    SELECT wposts.* 
    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    WHERE wposts.ID = wpostmeta.post_id 
    AND wpostmeta.meta_key = 'wpbl_availablity'
AND wpostmeta.meta_value = 'Rented'	
    AND wposts.post_type = 'library'
    ORDER BY wpostmeta.meta_value DESC
    ";


 $pageposts = $wpdb->get_results($querystr, OBJECT);

?>
 <?php if ($pageposts): ?>
  <?php global $post; ?>
  <h1 class="entry-title"><a href="<?php the_permalink() ?>" title="<?php printf(__("Permanent Link to %s", "wpbl"), the_title_attribute('echo=0')); ?>">This is the list for rented books and users.</a></h1> <br /><br />
<table border="5" cellpadding="5" cellspacing="15" width="99%" cols="6" id="booklist" class="booklist">
<tr border="1" id="booklist" class="booklist"><td><h3>Book ID:</h3></td><td width="300px" style="width:300px;"><h3>Title:</h3></td><td><h3>Authors</h3></td><td><h3>Category/Class</h3></td><td><h3>Book Publishers:</h3></td><td><h3>Editions:</h3></td><td><h3>Price</h3></td><td><h3>Received Date</h3></td><td><h3>From</h3></td><td><h3>List Date</h3></td><td><h3>Availablity</h3></td><td><h3>Borrower</h3></td></tr>
  <?php foreach ($pageposts as $post): ?>
    <?php setup_postdata($post); ?>
<?php 		$custom = get_post_custom($post->ID);
		$bookdate = $custom['bookdate'][0];
		$bookid= $custom['bookid'][0];
		$authors= $custom['bookauthors'][0]; 
		$price= $custom['price'][0];
		$receive_date= $custom['receive_date'][0];
		$receive_from= $custom['from'][0]; 	
		$availablity= $custom['wpbl_availablity'][0];
		$borrower= $custom['wpbl_user'][0];	 ?>


<tr><td><a href="<?php the_permalink() ?>" title="<?php printf(__("Permanent Link to %s", "wpbl"), the_title_attribute('echo=0')); ?>"><?php echo $bookid; ?></a></td>
<td style="width:400px;"><a href="<?php the_permalink() ?>" title="<?php printf(__("Permanent Link to %s", "wpbl"), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></td>

<td>
<?php the_terms( $post->ID, 'authors'); ?></td>
<td><?php the_terms( $post->ID, 'classcat'); ?></td>
<td><?php the_terms( $post->ID, 'publishers'); ?></td>
<td><?php the_terms( $post->ID, 'editions'); ?></td>
<td><?php echo $price; ?></td>
<td><?php echo $receive_date; ?></td>
<td><?php echo $receive_from; ?></td>
<td><?php echo $bookdate; ?></td>
<td><?php echo $availablity; ?></td>
<td><?php echo $borrower; ?></td>
</tr>


  <?php endforeach; ?>
  </table><br /> 
  	<?php
    if(function_exists('pagination')) { pagination(); }
    ?>
<br />
  <?php else : ?>
    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.</p>
    <?php include (TEMPLATEPATH . "/searchform.php"); ?>
 <?php endif; ?>



<?php get_footer(); ?>